package com.qyhl.webtv.commonlib.item.fuquan;

import android.content.Context;

import com.bumptech.glide.Glide;
import com.makeramen.roundedimageview.RoundedImageView;
import com.qyhl.webtv.basiclib.utils.glide.GlideOptionsUtils;
import com.qyhl.webtv.commonlib.R;
import com.qyhl.webtv.commonlib.entity.news.GlobalNewsBean;
import com.zhy.adapter.recyclerview.base.ItemViewDelegate;
import com.zhy.adapter.recyclerview.base.ViewHolder;

public class ItemFuQuanShop implements ItemViewDelegate<GlobalNewsBean> {
    private Context context;

    public ItemFuQuanShop(Context context) {
        this.context = context;
    }

    @Override
    public int getItemViewLayoutId() {
        return R.layout.item_panzhou_shop;
    }

    @Override
    public boolean isForViewType(GlobalNewsBean item, int position) {
        return "20".equals(item.getType());
    }

    @Override
    public void convert(ViewHolder holder, GlobalNewsBean globalNewsBean, int position) {
        holder.setText(R.id.title, globalNewsBean.getTitle());

        holder.setText(R.id.score, globalNewsBean.getOrigin());

        //封面图
        RoundedImageView cover = holder.getView(R.id.cover);
        Glide.with(context)
                .load(globalNewsBean.getCover())
                .apply(GlideOptionsUtils.getInstance().getOptions(R.drawable.cover_large_default, R.drawable.cover_large_default))
                .into(cover);

        if (globalNewsBean.getCommentNum() == 0) {//未下架
            if (globalNewsBean.getScanNum() == 0) {//售罄
                holder.setImageResource(R.id.sale_out, R.drawable.shop_sale_out_icon);
                holder.setVisible(R.id.sale_out, true);
                holder.setImageResource(R.id.exchange_btn, R.drawable.shop_exchange_btn_off);
            } else {
                holder.setVisible(R.id.sale_out, false);
                holder.setImageResource(R.id.exchange_btn, R.drawable.shopping_top_exchange_btn);
            }
        } else if (globalNewsBean.getCommentNum() == 3) {
            holder.setImageResource(R.id.sale_out, R.drawable.shop_sale_overdue_icon);
            holder.setVisible(R.id.sale_out, true);
            holder.setImageResource(R.id.exchange_btn, R.drawable.shop_exchange_btn_off);
        } else {
            holder.setImageResource(R.id.sale_out, R.drawable.shop_sale_off_icon);
            holder.setVisible(R.id.sale_out, true);
            holder.setImageResource(R.id.exchange_btn, R.drawable.shop_exchange_btn_off);
        }
    }
}
